<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<form class="datagrid-edit-form" data-toggle="validate" data-data-type="jsonp">
    <div class="bjui-row col-1">
  
         <label class="row-label">编号</label>
        <div class="row-input required">
            <input type="text" name="sto_lock_lcokNo"   data-rule="required">
        </div> 
       
        <label class="row-label">锁具型号</label>
        <div class="row-input required">
            <select id="sto_lock_type" name="obj.regname"  data-rule="required" >
           
            </select>
        </div>

      
    </div>
    <div class="bjui-pageFooter">
    <ul>
    	<li>
    		<button type="button" class="btn-close btn" data-icon="close">取消</button>
    	</li>
    	<li>
    		<button type="button" class="btn-default btn" data-icon="save" onclick="post_lock()">保存</button>
    	</li>
    	
    </ul>
    </div>
</form>
<script>

$(function(){

	BJUI.ajax('doajax',{
		url:'selectLockType',
	
		okCallback:function(data){
			var t = setTimeout(function() {
				for (var i = 0;i<data.length; i++)
				{
					$('#sto_lock_type').append('<option value='+data[i].tCode +'>'+ data[i].locType+'</option>');
				
					console.log(data[i]);
				}
			}, 50);

			console.log(data[0]);
		}
	})
});	

function post_lock(){
	var tcode = $('#sto_lock_type').val();
	var loc_no = $('[name="sto_lock_lcokNo"]').val();
	var ucode = '';
	if(loc_no == '')
		{
			BJUI.alertmsg('info','编号为空，请填写');
			return;
		}
	else{
		$.ajax({
			url:'addLock',
			data:{
				info:"[{" +
					"\"lockNo\":\""+loc_no+"\"}]",
				tCode:tcode,
				uCode:'2642e5a12b3246d5b487b9f182dd47a3'
			},
			success:function(data){
				var str = JSON.parse(data);
				if(str.check=='00'){
					BJUI.alertmsg('info','添加成功');
					$('#sto_message_id').datagrid('refresh',true);
					BJUI.dialog('closeCurrent');
				}
				else if(str.check=='10001'){
					BJUI.alertmsg('info','第'+ str.num+'条数据操作失败');
				}
				else if(str.check=='10002'){
					BJUI.alertmsg('info','第'+ str.num+'条数据已存在');
				}
			},
			error:function(data){
				alert('系统错误');
			}
		})
	}
	console.log(tcode);
	console.log(loc_no);
}	

</script>